<template>
	<view @click="open">
		<!-- 基础卡片 -->
		<view v-if="item.mode==='one'" class="listcard">
			<view class="listcard-header">
				<view class="listcard-header_image">
					 <image v-if="!item.avatar" src="https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg"></image>
					<image else :src="item.avatar"></image>
				</view>
				<view class="listcard-username">
					{{item.name||item.phone}}
				</view>
			</view>
			<view class="listcard-body">
				<view class="listcard-image">
					<image :src="item.pic[0]"></image>
				</view>
				<view class="listcard-content">
					<view class="listcard-content_title">
						<text>{{item.title||item.content}}</text>
					</view>
					<view class="listcard-content_date">
						<text>{{item.time | unix2Time}}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 多图卡片 -->
		<view v-if="item.mode==='more'" class="listcard mode-column">
			<view class="listcard-header">
				<view class="listcard-header_image">
					<image v-if="!item.avatar" src="https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg"></image>
					<image v-else :src="item.avatar"></image>
				</view>
				<view class="listcard-username">
					{{item.name||item.phone}}
				</view>
			</view>
			<view class="listcard-body">
				<view class="listcard-content">
					<view class="listcard-content_title">
						<text>{{item.title||item.content}}</text>
					</view>
				</view>
				<view class="listcard-image">
					<view v-if="index<3" v-for="(item,index) in item.pic" :key="index" class="listcard-image_item">
						<image :src="item"></image>
					</view>
				</view>
				<view class="listcard-content_date">
					<text>{{item.time | unix2Time}}</text>
				</view>
			</view>
		</view>

		<!-- 无图模式 -->
		<view v-if="item.mode==='no'" class="listcard mode-column">
			
			<view class="listcard-header">
				<view class="listcard-header_image">
					<image v-if="!item.avatar" src="https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg"></image>
					<image v-else :src="item.avatar"></image>
				</view>
				<view class="listcard-username">
					{{item.name||item.phone}}
				</view>
			</view>
			<view class="listcard-body">
				<view class="listcard-content">
					<view class="listcard-content_title">
						<text>{{item.title||item.content}}</text>
					</view>
				</view>
				<view  v-if="item.video" class="listcard-video">
					<video :src="item.video" controls></video>
				</view>
				<view class="listcard-content_date">
					<text>{{item.time | unix2Time}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default () {
					return []
				}
			},
			item: {
				type: Object,
				default () {
					return {}
				}
			},
			cx: {
				default () {
					return false
				}
			}


		},
		methods: {
			open() {
				// uni.showLoading()
				const item = this.item
				// console.log(item)
				this.$emit('click', item)
				this.$store.commit('changeComment',true)
				const params = {
					_id: item._id,
					avatar: item.avatar,
					name: item.name,
					title: item.title,
					time: item.time,
					u_id:item.u_id
				}
				if (this.cx) {
					uni.navigateTo({
						url:"../../pages/cx_detail/cx_detail?params=" + JSON.stringify(params)
					})

				} else {
					this.$emit('click', item)
					this.$store.commit('changeComment', true)
					uni.navigateTo({
						url: '/pages/details/details?params=' + JSON.stringify(params)
					})
				}

			}
		},
		mounted() {},
		data() {
			return {};
		}
	}
</script>

<style lang="scss">
	.listcard {
		position: relative;
		display: flex;
		flex-direction: column;
		margin: 10px;
		padding: 10px;
		border-radius: 5px;
		box-shadow: 0 0 5px 1px rgba($color: #000000, $alpha: 0.1);
		box-sizing: border-box;

		.listcard-header {
			display: flex;
			flex: 1;
			align-items: center;

			.listcard-header_image {
				flex-shrink: 0;
				width: 35px;
				height: 35px;
				border-radius: 50%;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.listcard-username {
				margin-left: 10px;
				color: #5a6e97;
				font-weight: bold;
			}
		}

		.listcard-body {
			display: flex;
			margin-top: 10px;

			.listcard-image {
				flex-shrink: 0;
				width: 60px;
				height: 60px;
				border-radius: 5px;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.listcard-content {
				padding-left: 10px;
				width: 100%;

				.listcard-content_title {
					font-size: 14px;
					color: #333;
					font-weight: bold;

					text {
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
					}
				}

				.listcard-content_date {
					display: flex;
					justify-content: flex-end;
					margin-top: 7px;

					text {
						margin-top: 17px;
					}

				}
			}
		}

		&.mode-column {
			.listcard-body {
				display: flex;
				flex-direction: column;

				.listcard-content {
					width: 100%;
					padding-left: 0;
				}

				.listcard-content_date {
					display: flex;
					justify-content: flex-end;
					margin-top: 5px;
				}
				.listcard-video{
					margin:10px auto;
				}
				.listcard-image {
					display: flex;
					margin-top: 10px;
					width: 100%;
					height: 70px;

					.listcard-image_item {
						margin-left: 10px;
						width: 100%;
						border-radius: 5px;
						overflow: hidden;

						&:first-child {
							margin-left: 0;
						}

						image {
							width: 100%;
							height: 100%;
						}
					}
				}
			}


		}
	}
</style>
